import React, { Component } from 'react'
import {
  Platform,
  StyleSheet,
  Text,
  View,
} from 'react-native'
import * as storage from '../utils/storage'

export default class Read extends Component {
  componentDidMount () {
    const { book } = this.props.navigation.state.params
    storage.getItem('readHistory')
      .then(data => {
        if (data === null) {
          const readHistory = {
            [book.strBookId]: {
              title: book.title,
              imageUrl: book.imageUrl
            }
          }
          storage.setItem('readHistory', JSON.stringify(readHistory))
        } else {
          let readHistory = JSON.parse(data)
          if (!readHistory.hasOwnProperty(book.strBookId)) {
            readHistory[book.strBookId] = {
              title: book.title,
              imageUrl: book.imageUrl
            }
          }
          storage.setItem('readHistory', JSON.stringify(readHistory))
        }
      })
  }
  render () {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Read</Text>
      </View>
    )
  }
}